package com.mlick.a.leetcode;

/**
 * @author lixiangxin
 * @date 2022/1/4 15:11
 * https://leetcode.com/problems/day-of-the-week/
 **/
public class A1185 {

    /**
     * 整体思路: 给定1971年到2100年， 计算当前日期与1970年最后一天的天数（星期四）总天数，最后取模就可得出具体星期
     */
    static String[] ws = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    static int[] nums = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    public String dayOfTheWeek(int day, int month, int year) {
        int startW = 4;

        for (int i = 1971; i < year; i++) {
            boolean isleap = (i % 4 == 0 && i % 100 != 0) || i % 400 == 0;
            startW += isleap ? 366 : 365;
        }

        for (int i = 1; i < month; i++) {
            startW += nums[i - 1];
            if (i == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) {
                startW++;
            }
        }

        startW += day;

        return ws[startW % 7];
    }

    public static void main(String[] args) {
        // System.out.println(new LC1185().dayOfTheWeek(31, 8, 2019));
        // System.out.println(new LC1185().dayOfTheWeek(18, 7, 1999));
        // System.out.println(new LC1185().dayOfTheWeek(15, 8, 1993));
        // System.out.println(new LC1185().dayOfTheWeek(29, 2, 2000));
    }
}
